package yazan.com.pdacollector_android.adapter;

import android.content.Context;
import android.support.annotation.Nullable;

import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.text.SimpleDateFormat;
import java.util.List;

import yazan.com.pdacollector_android.R;
import yazan.com.pdacollector_android.model.OrderBrowserInfo;
import yazan.com.pdacollector_android.utils.PDAGlobal;

public class OrderBrowserAdapter extends BaseQuickAdapter<OrderBrowserInfo, BaseViewHolder> {
    private Context context;
    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    public OrderBrowserAdapter(int layoutResId, @Nullable List<OrderBrowserInfo> data, Context context) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderBrowserInfo item) {
        if (helper.getAdapterPosition() == PDAGlobal.selectPositionForBrowser) {
            helper.itemView.setBackgroundColor(context.getResources().getColor(R.color.colorRed));
        } else {
            if (item.getForder_status() == 2) {
                helper.itemView.setBackgroundColor(context.getResources().getColor(R.color.darkgray));
            } else {
                helper.itemView.setBackgroundColor(context.getResources().getColor(R.color.colorWhite));
            }
        }

        helper.setText(R.id.tvIndex, (helper.getPosition() + 1) + "");
        helper.setText(R.id.tvUniqueCode, item.getForder_id() + "");
        helper.setText(R.id.tvOrderCode, item.getForder_sn());
        helper.setText(R.id.tvType, item.getForder_status() == 3 ? "未上传" : item.getForder_status() == 1 ? "未完成" : "已完成");
        helper.setText(R.id.tvOldTime, item.getFexa_date() == null ? "" : TimeUtils.date2String(item.getFexa_date(), dateFormat));
        helper.setText(R.id.tvTime, item.getForder_date() == null ? "" : TimeUtils.date2String(item.getForder_date(), dateFormat));
    }
}
